package org.opens.service;

import org.opens.constant.RedisCacheKey;
import org.opens.entity.RedisCacheEntity;
import org.opens.entity.RedisCacheSaveDTO;
import org.opens.entity.RedisCacheUpdateDTO;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;

/**
 * 功能:
 *
 * @author zym
 * @Date 2022/6/28 15:35
 */
// @CacheConfig(cacheNames = "redisCache")
public interface RedisCacheService {

    /**
     * 保存缓存对象
     * @param redisCacheSaveDTO 待保存的缓存对象
     * @return true: 保存成功, false: 保存失败
     */
    RedisCacheEntity save(RedisCacheSaveDTO redisCacheSaveDTO);

    /**
     * 根据id删除对应的对象
     * @param id 操做id
     * @return true: 删除成功, false: 删除失败
     */
    /*@Caching(evict = {
            @CacheEvict(value = "redisCache", allEntries = true)
    })*/
    @CacheEvict(cacheNames = RedisCacheKey.KEY)
    boolean delete(Integer id);

    /**
     * 根据id更新缓存对象的信息
     * @param redisCacheUpdateDTO 缓存对象
     * @return true: 更新成功, false: 更新失败.
     */
    @CachePut(cacheNames = RedisCacheKey.KEY)
    RedisCacheEntity update(RedisCacheUpdateDTO redisCacheUpdateDTO);

    /**
     * 根据id来查询信息
     * @param id 操做id
     * @return 查询到的实体vo信息
     */
    @Cacheable(cacheNames = RedisCacheKey.KEY, unless="#result == null")
    RedisCacheEntity selectById(Integer id);

}
